#pragma once

namespace AVUI {

/// <summary>Provides data related to the <see cref="E:System.Windows.FrameworkElement.SizeChanged" /> event. </summary>
class SizeChangedEventArgs : public RoutedEventArgs
{
public:
    DECLARE_ELEMENT(SizeChangedEventArgs, RoutedEventArgs);

#pragma region Public Properties

    /// <summary>Gets a value that indicates whether the <see cref="P:System.Windows.FrameworkElement.Height" /> component of the size changed.</summary>
    /// <returns>true if the <see cref="P:System.Windows.FrameworkElement.Height" /> component of the size changed; otherwise, false.</returns>
    bool get_HeightChanged() { return (m_bits & m_heightChangedBit) != 0; }

    /// <summary>Gets the new <see cref="T:System.Windows.Size" /> of the object.</summary>
    /// <returns>The new <see cref="T:System.Windows.Size" /> of the object.</returns>
    Size get_NewSize() { return m_pElement->get_RenderSize(); }

    /// <summary>Gets the previous <see cref="T:System.Windows.Size" /> of the object. </summary>
    /// <returns>The previous <see cref="T:System.Windows.Size" /> of the object.</returns>
    Size get_PreviousSize() { return m_previousSize; }

    /// <summary>Gets a value that indicates whether the <see cref="P:System.Windows.FrameworkElement.Width" /> component of the size changed.</summary>
    /// <returns>true if the <see cref="P:System.Windows.FrameworkElement.Width" /> component of the size changed; otherwise, false.</returns>
    bool get_WidthChanged() { return (m_bits & m_widthChangedBit) != 0; }

#pragma endregion Public Properties

public:

#pragma region Internal Methods

    SizeChangedEventArgs(UIElement* pElement, SizeChangedInfo* pInfo) : m_bits(0)
    {
        if (pInfo == NULL)
        {
            LibraryCriticalError();
        }
        if (pElement == NULL)
        {
            LibraryCriticalError();
        }
        m_pElement = pElement;
        m_previousSize = pInfo->get_PreviousSize();
        if (pInfo->get_WidthChanged())
        {
            m_bits = (unsigned char) (m_bits | m_widthChangedBit);
        }
        if (pInfo->get_HeightChanged())
        {
            m_bits = (unsigned char) (m_bits | m_heightChangedBit);
        }
    }
 
#pragma endregion Internal Methods

private:

#pragma region Private Fields

    unsigned char m_bits;
    TRefCountedPtr<UIElement> m_pElement;
    Size m_previousSize;
    static const unsigned char m_heightChangedBit = 2;
    static const unsigned char m_widthChangedBit = 1;

#pragma endregion Private Fields

};

DEFINE_EVENTHANDLER(SizeChanged);

}; 


